package fr.paulmasson.jfreex.ui;

import org.eclipse.swt.browser.Browser;

import fr.paulmasson.jfreex.channels.LiveChannel;
import fr.paulmasson.jfreex.channels.LiveChannel.Definition;
import fr.paulmasson.jfreex.replay.ReplayChannel;

public class Links implements ChannelsListListener {

	private VlcPlayer player;
	private InfosPanel ip;
	private Browser browser;
	private ChannelsList channelList;

	public Links(VlcPlayer player, InfosPanel ip, ChannelsList channelsList) {
		this.channelList = channelsList;
		channelsList.addChannelsListListener(this);
		ip.addChannelsListListener(this);
		this.player = player;
		this.ip = ip;
	}
	
	public Links(Browser browser, ReplayList replaysList) {
		replaysList.addChannelsListListener(this);
		this.browser = browser;
	}
	
	@Override
	public void ChannelChanged(LiveChannel channel) {
		this.player.playMedia(channel.getUrl());		
		this.ip.update(channel);
	}

	@Override
	public void ChannelChanged(ReplayChannel channel) {
		this.browser.setUrl(channel.getUrl());		
	}

	@Override
	public void ChannelChanged(LiveChannel channel, Definition def) {
		this.player.playMedia(channel.getUrl(def));		
		channel.setCurrentDef(def);
		this.ip.update(channel);		
	}

	@Override
	public void ChannelStopped() {
		this.player.stopMedia();		
	}

	@Override
	public void audioVolumeChange(int vol) {
		this.player.setVolume(vol);
	}

	@Override
	public void pause() {
		this.player.pauseMedia();
		
	}

	@Override
	public void play() {
		this.player.playMedia();
	}

	@Override
	public void backToLive() {
		this.player.stopMedia();
		this.player.playMedia();
	}

}
